import { RedisModule as NestRedisModule, RedisClientOptions } from '@liaoliaots/nestjs-redis'
import { Global, Module } from '@nestjs/common'
import { ConfigModule, ConfigService } from '@nestjs/config'
import { ConfigKeyPaths } from '@/config'
import { RedisService } from './redis.service'
@Global()
@Module({
	imports: [
		// redis
		NestRedisModule.forRootAsync({
			imports: [ConfigModule],
			useFactory: (config: ConfigService<ConfigKeyPaths>) => {
				const redisConfig = config.get<RedisClientOptions>('redis')
				return {
					readyLog: true,
					config: redisConfig,
				}
			},
			inject: [ConfigService],
		}),
	],
	providers: [RedisService],
	exports: [RedisService],
})
export class RedisModule {}
